<?php

namespace app\modules\home\controllers;

use Yii;
use app\controllers\ApiBaseController;
use app\modules\home\actions as actions;
// use function yii\redis\time;

class HomeController extends ApiBaseController {
    
    public function init(){
        
    }
    
    public function actionSetsession() {
        $data = [
            'value'=>100,
            'expire_time'=>time()+10, //10秒过期时间
        ];
        
        yii::$app->session['test'] = $data;
        
        return 10;
    }
    
    public function actionGetsession() {
        $session_test = yii::$app->session['test'];
        return $session_test;
    }
    
    public function actionSample() {
        $get = Yii::$app->request->get();
        var_dump($get);
        
        
        $action = new actions\User();
        $ret = $action->Userlogin($get);
        if($ret) {
            $cookie = new \yii\web\Cookie();
            $cookie->name = 'uid';
            $cookie->value = $ret;
            $cookie->expire = time() + 30*24*3600; //一个月过期时间
            
            Yii::$app->response->cookies->add($cookie);
            Yii::$app->response->send();
        }
        return $ret;
        
        
//         // 从 "response" 组件中获取 cookie 集合(yii\web\CookieCollection)
//         $cookies = Yii::$app->request->cookies;
        
//         $uid = $cookies->getValue('uid');
//         return $uid;
        
//         // 在要发送的响应中添加一个新的 cookie
//         $cookies->add(new \yii\web\Cookie([
//             'name' => 'language',
//             'value' => 'zh-CN',
//         ]));
        
//         var_dump($cookies);
//         return true;
    }
}